<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
    export default {
        mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.Edit],
        components: {
            SelectAddress: async () => Vue.extend(await Vue.prototype.$vFN.Components.Base.SelectAddress())
        },
        data() {
            return {
                appWindow: window,
                msgTypeList: [{
                        icon: "el-icon-document",
                        label: 'text',
                        text: '文本',
                    },
                    {
                        icon: "el-icon-picture-outline-round",
                        label: 'image',
                        text: '图片'
                    },
                    {
                        icon: "el-icon-microphone",
                        label: 'voice',
                        text: '语音'
                    },
                    {
                        icon: "el-icon-video-camera",
                        label: 'video',
                        text: '视频'
                    },
                    {
                        icon: "el-icon-postcard",
                        label: 'news',
                        text: '图文'
                    },
                ],
                // 内容
                content: {
                    text: "",
                    image: null,
                    voice: null,
                    video: null,
                    news: null,
                },
                form: {
                    // 回复类型 1关注 2默认 3关键词
                    replyType: 2,
                    // 是否开启 0否 1是
                    isOpen: 1,
                    // 规则名称
                    name: "",
                    // 内容类型 文本text 图片 image 语音 voice 视频 video 图文 news
                    msgType: "text",
                    // 匹配类型 1精确 2模糊
                    matchType: 1,
                    // 回复的消息内容  msgType=text时传
                    content: "",
                    // 资源 msgType=image、voice、video、news 时传
                    albumInfoId: "",
                },

                // 页面接口地址
                apiUrl: {
                    create: "mall-site-portal/wechat-mp-reply/create",
                    update: "mall-site-portal/wechat-mp-reply/update",
                    detail: "mall-site-portal/wechat-mp-reply/getItem",
                },
            };
        },
        methods: {
            selectImage() {
                this.$vFN.Directives.SelectResourcesImage({
                    appWindow: this.appWindow,
                    count: 1,
                    mode: "wx",
                    onSuccess: (res) => {
                        this.content.image = res.all.obj[0]
                    },
                });
            },
            selectVideo() {
                this.$vFN.Directives.SelectResourcesVideo({
                    appWindow: this.appWindow,
                    count: 1,
                    mode: "wx",
                    onSuccess: (res) => {
                        this.content.video = res.all.obj[0]
                    },
                });
            },
            selectVoice() {
                this.$vFN.Directives.SelectResourcesAudio({
                    appWindow: this.appWindow,
                    count: 1,
                    mode: "wx",
                    onSuccess: (res) => {
                        this.content.voice = res.all.obj[0]
                    },
                });
            },
            selectTuwen() {
                this.$vFN.Directives.SelectResourcesWxTuwen({
                    appWindow: this.appWindow,
                    count: 1,
                    mode: "wx",
                    onSuccess: (res) => {
                        console.error(res.all)
                        this.content.news = res.all.obj[0]
                    },
                });
            },

            // 初始化
            async init() {
                // 初始化数据
                await this.mixinEdit_editBoxInit({
                    model: "form",
                    id: this.id,
                })
            },
       
            // form 提交添加/修改 的参数扩展方法 返回false 则不提交用于扩展验证
            mixinEdit_editFormSubmitExtend(data_) {
                console.error("_data", data_, this.content)
                if (data_.msgType == "text") {
                    data_.content = this.content.text
                } else if (data_.msgType == "image") {
                    data_.albumInfoId = this.content.image.id

                } else if (data_.msgType == "video") {
                    data_.albumInfoId = this.content.video.id
                } else if (data_.msgType == "voice") {
                    data_.albumInfoId = this.content.voice.id
                }
                else if (data_.msgType == "news") {
                    data_.albumInfoId = this.content.news.id
                }

                return data_
            },
            // 编辑修改的参数扩展方法
            mixinEdit_editDataExtend(data_) {
                console.error(data_)
                // 添加
                if (this.mixinEdit_editType == "add") {}
                // 修改
                else if (this.mixinEdit_editType == "update") {
                    if (data_.msgType == "text") {
                        this.content.text = data_.content;
                    } else if (data_.msgType == "image") {
                        this.content.image = data_.albumInfo

                    } else if (data_.msgType == "video") {
                        this.content.video = data_.albumInfo
                    } else if (data_.msgType == "voice") {
                        this.content.voice = data_.albumInfo
                    }
                    else if (data_.msgType == "news") {
                        this.content.news = data_.albumInfo
                    }
                }
                return data_
            },
      

        },
        mounted() {
            this.init();
        },
        activated() {},
    };
</script>
